package com.yanqu.road.server.cmd.activity.peakseacraft;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakSeacraftProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.peakseacraft.PeakSeacraftModule;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.peakseacraft.PeakSeacraftMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;

/**
 * @Description
 */
@Cmd(code = GameProtocol.S_PEAK_SEACRAFT_BUY_BUFF, desc = "海上争霸 南海丝路 购买buff")
public class PeakSeacraftBuyBuffCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PeakSeacraftProto.PeakSeacraftBuyBuffReqMsg reqMsg = PeakSeacraftProto.PeakSeacraftBuyBuffReqMsg.parseFrom(packet.getBytes());
        ActivityInfo activityInfo = ActivityMgr.getOpenActivityInfo(reqMsg.getActivityId());
        if (null == activityInfo){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if (activityInfo.getType() == eActivityType.PeakSeacraftActivity.getValue()) {
            ret = player.getModule(PeakSeacraftModule.class).buyBuff(reqMsg);
        } else {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            PeakSeacraftProto.PeakSeacraftBuyBuffRespMsg.Builder resp = PeakSeacraftProto.PeakSeacraftBuyBuffRespMsg.newBuilder();
            resp.setRet(ret);
            player.sendPacket(ClientProtocol.U_PEAK_SEACRAFT_BUY_BUFF,resp);
        }
    }
}
